package 力扣日常刷题.木22一月.第16天0128;

import 力扣日常刷题.ListNode;

import java.util.Stack;

/**
 * @author 帅小伙
 * @date 2022/1/28
 * @description
 */
public class Demo13JZ从尾打印链表 {

    public int[] reversePrint(ListNode head) {

        Stack<Integer> stack = new Stack<Integer>();
        while(head != null) {
            stack.push(head.val);
        }
        int[] ans = new int[stack.size()];
        for (int i = 0; i < ans.length; i++) {
            ans[i] = stack.pop();
        }
        return ans;
    }

}
